package com.example.controller;

import com.example.commom.R;
import com.example.domain.User;
import com.example.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService iUserService;
    @PostMapping(value = "/login", consumes = "application/json")
    public R login(@RequestBody User user){
        Map<String,Object> map = iUserService.login(user);
        if (!map.get("token").equals("")&&!map.get("username").equals("")){
            return R.ok().message("登陆成功").data("map",map);
        }
        return R.error().message("登陆失败");
    }
}
